package com.suao.web.controller.report;

import com.suao.common.annotation.Log;
import com.suao.common.core.controller.BaseController;
import com.suao.common.core.domain.AjaxResult;
import com.suao.common.core.page.TableDataInfo;
import com.suao.common.enums.BusinessType;
import com.suao.common.utils.poi.ExcelUtil;
import com.suao.report.domain.VGoodsSalesInfo;
import com.suao.report.service.IVGoodsSalesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 商品销售统计Controller
 *
 * @author tyz
 * @date 2023-03-02
 */
@RestController
@RequestMapping("/report/goods")
public class VGoodsSalesInfoController extends BaseController
{
    @Autowired
    private IVGoodsSalesInfoService vGoodsSalesInfoService;

    /**
     * 查询商品销售统计列表
     */
    @PreAuthorize("@ss.hasPermi('report:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(VGoodsSalesInfo vGoodsSalesInfo)
    {
        startPage();
        List<VGoodsSalesInfo> list = vGoodsSalesInfoService.selectVGoodsSalesInfoList(vGoodsSalesInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品销售统计列表
     */
    @PreAuthorize("@ss.hasPermi('report:goods:export')")
    @Log(title = "商品销售统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VGoodsSalesInfo vGoodsSalesInfo)
    {
        List<VGoodsSalesInfo> list = vGoodsSalesInfoService.selectVGoodsSalesInfoList(vGoodsSalesInfo);
        ExcelUtil<VGoodsSalesInfo> util = new ExcelUtil<VGoodsSalesInfo>(VGoodsSalesInfo.class);
        util.exportExcel(response, list, "商品销售统计数据");
    }

    /**
     * 获取商品销售统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:goods:query')")
    @GetMapping(value = "/{salesTime}")
    public AjaxResult getInfo(@PathVariable("salesTime") Date salesTime)
    {
        return success(vGoodsSalesInfoService.selectVGoodsSalesInfoBySalesTime(salesTime));
    }

    /**
     * 新增商品销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:goods:add')")
    @Log(title = "商品销售统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VGoodsSalesInfo vGoodsSalesInfo)
    {
        return toAjax(vGoodsSalesInfoService.insertVGoodsSalesInfo(vGoodsSalesInfo));
    }

    /**
     * 修改商品销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:goods:edit')")
    @Log(title = "商品销售统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VGoodsSalesInfo vGoodsSalesInfo)
    {
        return toAjax(vGoodsSalesInfoService.updateVGoodsSalesInfo(vGoodsSalesInfo));
    }

    /**
     * 删除商品销售统计
     */
    @PreAuthorize("@ss.hasPermi('report:goods:remove')")
    @Log(title = "商品销售统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{salesTimes}")
    public AjaxResult remove(@PathVariable Date[] salesTimes)
    {
        return toAjax(vGoodsSalesInfoService.deleteVGoodsSalesInfoBySalesTimes(salesTimes));
    }
}
